$(function () {
    $("#jqGrid").jqGrid({
        url: '../trainingimplementationmanagement/list',
        datatype: "json",
        colModel: [			
			{ label: 'id', name: 'id', index: 'id', width: 50, key: true ,hidden:true},
			{ label: '年度', name: 'year', index: 'year', width: 80 }, 			
			{ label: '课程名称', name: 'courseName', index: 'course_name', width: 80 },
			{ label: '学习形式', name: 'learningType', index: 'Learning_type', width: 80 }, 			
			{ label: '组织部门', name: 'organizationDepartment', index: 'Organization_Department', width: 80 }, 			
			{ label: '组织部门id', name: 'organizationDepartmentId', index: 'Organization_Department_id', width: 80,hidden:true },
			{ label: '培训对象', name: 'trainingTarget', index: 'Training_target', width: 80 }, 			
			{ label: '课程安排', name: 'courseArrangement', index: 'course_arrangement', width: 80 }, 			
			{ label: '预计日期', name: 'estimatedTime', index: 'Estimated_time', width: 90, formatter:"date", formatoptions: {newformat:'Y-m-d'}  },
            { label: '实施日期', name: 'implementationDate', index: 'implementation_date', width: 90, formatter:"date", formatoptions: {newformat:'Y-m-d'}  },

            { label: '授课人', name: 'lecturer', index: 'Lecturer', width: 80 },
			{ label: '参加人数', name: 'participantsNumber', index: 'participants_Number', width: 80 }, 			
			{ label: '培训结果', name: 'trainingResult', index: 'Training_result', width: 80 ,
               },
        ],
		viewrecords: true,
        height: 385,
        rowNum: 10,
		rowList : [10,30,50],
        rownumbers: true, 
        rownumWidth: 25, 
        autowidth:true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page", 
            rows:"limit", 
            order: "order"
        },
        gridComplete:function(){
        	//隐藏grid底部滚动条
        	$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" }); 
        }
    });
});

var vm = new Vue({
	el:'#rrapp',
	data:{
        q: {
            organizationDepartment: null,
            year: null
        },
		showList: true,
        showtable:false,
		title: null,
		trainingImplementationManagement: {}
	},
	methods: {
		query: function () {
			vm.reload();
		},
		add: function(){
			vm.showList = false;
            vm.showtable = false;
			vm.title = "新增";
			vm.trainingImplementationManagement = {};
		},
		update: function (event) {
			var id = getSelectedRow();
			if(id == null){
				return ;
			}
			vm.showList = false;
            vm.showtable = false;
            vm.title = "修改";
            
            vm.getInfo(id)
		},
		saveOrUpdate: function (event) {
           /* vm.trainingImplementationManagement.estimatedTime=$("#estimatedTime").val();
            vm.trainingImplementationManagement.implementationDate=$("#implementationDate").val();*/
            // vm.trainingImplementationManagement.year=$("#year").val();
            var url = vm.trainingImplementationManagement.id == null ? "../trainingimplementationmanagement/save" : "../trainingimplementationmanagement/update";
			$.ajax({
				type: "POST",
			    url: url,
			    contentType: "application/json",
			    data: JSON.stringify(vm.trainingImplementationManagement),
			    success: function(r){
			    	if(r.code === 0){
						alert('操作成功', function(index){
							vm.reload();
						});
					}else{
						alert(r.msg);
					}
				}
			});
		},
		del: function (event) {
			var ids = getSelectedRows();
			if(ids == null){
				return ;
			}
			
			confirm('确定要删除选中的记录？', function(){
				$.ajax({
					type: "POST",
				    url: "../trainingimplementationmanagement/delete",
				    contentType: "application/json",
				    data: JSON.stringify(ids),
				    success: function(r){
						if(r.code == 0){
							alert('操作成功', function(index){
								$("#jqGrid").trigger("reloadGrid");
							});
						}else{
							alert(r.msg);
						}
					}
				});
			});
		},
		getInfo: function(id){
			$.get("../trainingimplementationmanagement/info/"+id, function(r){
                vm.trainingImplementationManagement = r.trainingImplementationManagement;
            });
		},
		reload: function (event) {
			vm.showList = true;
            vm.showtable = false;
			var page = $("#jqGrid").jqGrid('getGridParam','page');
			$("#jqGrid").jqGrid('setGridParam',{
                postData:{
                    'year': vm.q.year, 'estimatedTime1': vm.q.estimatedTime1, 'estimatedTime2': vm.q.estimatedTime2,
                    'organizationDepartment': vm.q.organizationDepartment},
                page:page
            }).trigger("reloadGrid");


		},
        fillResult: function (event) {
            var id = getSelectedRow();
            if(id == null){
                return ;
            }

            vm.showList = false;
            vm.showtable = true;
            vm.title = "培训结果";

            vm.getInfo(id)
            // $("#implementationDate").val(vm.trainingImplementationManagement.implementationDate);

        },
	}
});

function endDate(value){
    vm.trainingImplementationManagement.implementationDate=value;
}
function zfDate(value){
    vm.trainingImplementationManagement.estimatedTime=value;
}

function yearChange(value){
    vm.trainingImplementationManagement.year=value;
}

function zfDate1(value){
    vm.q.estimatedTime1=value;
}
function zfDate2(value){
    vm.q.estimatedTime2=value;
}